import Vue from 'vue'
import Vuex from 'vuex'
import {getItem,setItem} from '@/utils/storage'

Vue.use(Vuex)
const TOKEN_KEY = 'TOUTIAO_USER'

export default new Vuex.Store({
  state: {
    // 一个是对象 存储当前登录的用户信息 token灯信息
    user: getItem(TOKEN_KEY)
    // user: JSON.parse(window.localStorage.getItem(TOKEN_KEY))
  },
  getters: {
  },
  mutations: {
    setUser(state,data){
      state.user = data

      // 为了防止刷新丢失，需要把数据备份到本地存储
      setItem(TOKEN_KEY,state.user)
      // window.localStorage.setItem('TOUTIAO_USER', JSON.stringify(state.user))
    }
  },
  actions: {

  },
  modules: {
  }
})
